package com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.custom;

import com.tengju.user.infrastructure.persistence.mybatis.dataobject.ZoneDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ZoneMapper {

    @Insert({
            "insert into user_zone_meta (name, head_img, create_by, update_by, create_time, update_time)",
            "values (#{name}, #{headImg}, #{createBy}, #{updateBy}, #{createTime}, #{updateTime})"
    })
    int insert(ZoneDO zoneDO);

    @Select("select * from user_zone_meta limit #{offset},#{limit}")
    @Results(value = {
                    @Result(column = "id", property = "id"),
                    @Result(column = "name", property = "name"),
                    @Result(column = "head_img", property = "headImg"),
                    @Result(column = "create_by", property = "createBy"),
                    @Result(column = "update_by", property = "updateBy"),
                    @Result(column = "create_time", property = "createTime"),
                    @Result(column = "update_time", property = "updateTime"),
            })
    List<ZoneDO> queryByPage(@Param("offset") Integer offset,@Param("limit") Integer pageSize);


    @Select("select * from user_zone_meta where name = #{name}")
    @Results(value = {
                    @Result(column = "id", property = "id"),
                    @Result(column = "name", property = "name"),
                    @Result(column = "head_img", property = "headImg"),
                    @Result(column = "create_by", property = "createBy"),
                    @Result(column = "update_by", property = "updateBy"),
                    @Result(column = "create_time", property = "createTime"),
                    @Result(column = "update_time", property = "updateTime"),
            })
    ZoneDO queryByName(@Param("name") String name);

    @Select("select count(*) from user_zone_meta")
    Integer count();

    @Select("select * from user_zone_meta where id = #{zoneId}")
    @Results(value = {
                    @Result(column = "id", property = "id"),
                    @Result(column = "name", property = "name"),
                    @Result(column = "head_img", property = "headImg"),
                    @Result(column = "create_by", property = "createBy"),
                    @Result(column = "update_by", property = "updateBy"),
                    @Result(column = "create_time", property = "createTime"),
                    @Result(column = "update_time", property = "updateTime"),
            })
    ZoneDO queryById(@Param("zoneId") Long zoneId);

    @Update("update user_zone_meta set name = #{name}, head_img = #{headImg}, update_by = #{updateBy} where id = #{id}")
    int updateNameAndHeadImg(ZoneDO zoneDO);


    @Delete("delete from user_zone_meta where id = #{zoneId}")
    int delete(@Param("zoneId") Long zoneId);
}
